
/****************************************************************************
**
** Copyright (C) 2004-2008 VATATA.com . All rights reserved.
**
** This file is the part of the Miniutil Poject of VATATA.com.
** Vatata's miniutil library is lightweight and portable (for linux
** and Windows). The C++ Class Library included Threadpool, Dll danymic loading, 
** General socket application model and tcp server, httpserver/servlet, etc. 
** It is a pratical utility disigned for who don't want learn the Big C++ 
** Developing Platform, such as  Boost or ACE.
**
** This file may be used under the terms of the GNU General Public
** License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file.  Alternatively you may (at
** your option) use any later version of the GNU General Public
** License if such license has been publicly approved by VATATA.com.
** (or its successors, if any) and the Miniutil Project Aministrators. 
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://www.gnu.org/licenses/lgpl.html. If you are unsure which 
** license is appropriate for your use, please review the following 
** information: http://code.google.com/p/miniutil/ or contact 
** http://www.vatata.com.
**
** In addition, as a special exception, VATATA.com, as the sole
** copyright holder for Miniutil Project, grants users of VATATA
** P2P Platform the right to release and package with the related 
** libraries without the source code.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. vatata reserves all rights not expressly
** granted herein.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/



#include "minitest/testcase.h"

#include "miniutil/usocket.h"
#include "miniutil/address.h"
#include "miniutil/log.h"

#ifdef WIN32
# include <winsock2.h>
#include "windows.h"
#endif

#include <iostream>

#include <string>


using namespace miniutil;

testmain themain;

//void p2pserver( int port );

extern testcase * taddress1;
extern testcase * tthread1;
extern testcase * thttpclient1;
extern testcase * tthreadpool1;
extern testcase * thttpserver1;
extern testcase * turl1;
extern testcase * tusocket1;
extern testcase * tprocesstest1;
extern testcase * dirtest;
extern testcase * testpattern1;
extern testcase * teststorage1 ;
extern testcase * ptestdirfile1;
extern testcase * trefptr;
extern testcase * rudpd ;

extern testcase * t_srtti_1 ;
extern testcase * thttpserver2;

//extern testcase * test_ioselect ;

extern testcase * t_exception_instance;

extern testcase * p_t_asyncnet;

extern testcase * p_sha1_test;
//extern void clean_dir(const char * dir_name  , miniutil::m_int64_t max_bytes );

#include "miniutil/base64.h"
#include "miniutil/tinyxml.h"
#include "miniutil/url.h"


int main(int argc, char ** argv)
{

    L_DEBUG("test started\r\n");
    
	//tthread1->test();
	tthreadpool1->test();
    
    return 0;
	
    p_sha1_test->test();

    return 0;

    p_t_asyncnet->test();

    string str("Ȼÿ˳ѡ64ٰ֮6ǰ}0??ͳһµֽڡ֮ѡ640ӣ4ƣֱ24");

    string estr = miniutil::util::base64::encode( str );
    cout << estr << endl;

    string res = miniutil::util::base64::decode( estr )->data();

    cout << res << endl;

    if ( res == str ) 
        cout << "ok\n";
    else
        cout << "fail\n";

//    p_t_asyncnet->test();

 //   clean_dir("e:\\temp\\tmp", 1000 * 1000 );

    //t_exception_instance->test();

    return 1;

	//test_ioselect->test();

	return 1;
	taddress1->test();

	return 1;


	//tthread1->test();
	tthreadpool1->test();

	return 1;

	M_TRACE_LINE("");
	trefptr->test();

	return 1;

	t_srtti_1->test();

	

	return 1;

	thttpserver2->test();
	return 1;


	//rudpd->test();
	return 1;


	ptestdirfile1->test();

	return 1;
	teststorage1->test();


	tprocesstest1->test();

	testpattern1->test();

	dirtest->test();

	tusocket1->test();

	turl1->test();



	//test_update();

	//tprocesstest1->test();

	//tusocket1->test();

	//turl1->test();

	//taddress1->test();

	//tthread1->test();


	//thttpclient1->test();




	//thttpserver1->test();


//	Sleep(100000);

	return 0;
}


/*
bool wget_download_file(const char * wget_cmd, const char * remote_url, const char * local_path)
{
	char buf[10000];
	sprintf( buf, "%s -c -P \"%s\" %s", wget_cmd, local_path, remote_url );
	cout << "exec cmd " << buf << " \t ";

	process * p = process::create( string(buf) );

	if ( p == NULL || ! p->isRunning() )
	{
		cout << " failed" << endl;
		return false;
	}

	cout << " starting" << endl;

	int size = 0;
	long totalSize = 0;
	bool startFlag = false;
	int downloadCount = 0;

	while( (size=p->readerr( buf, 999 )) > 0 )
	{
		buf[size] = '\0';
		if ( totalSize == 0 )
		{
			char *p = strstr(buf, "Length: ");
			if ( p != NULL )
			{
				char *start = p + 8;
				char digitbuf[100];
				int i=0;
				while( i<100 )
				{
					if ( isalpha( *start ) )
						digitbuf[i++] = *start;
					else if ( *start != ',' )
					{
						digitbuf[i] = '\0';
						break;
					}
					start ++;
				}
				if ( i > 0 )
					totalSize = atoi( digitbuf );
				cout << "total size : " << totalSize << endl;
			}
		}
		if ( startFlag == false )
		{
			char *p = strstr( buf, "skipping" ) ;
			if ( p != NULL )
			{
				downloadCount = atoi(p + 9);

				char * start = p + 2;
				while( *start )
				{
					if ( *start == '.' || *start == ',' )
						downloadCount ++;
					start ++;
				}
				startFlag = true;
			cout << "Download size: " << downloadCount * 1024 << endl;
			}
			else
			{
				p = strstr(buf, "0K");
				if ( p != NULL )
				{
					char * start = p + 2;
					while( *start )
					{
						if ( *start == '.' || *start == ',' )
							downloadCount ++;
						start ++;
					}
					startFlag = true;
				cout << "Download size: " << downloadCount * 1024 << endl;
				}
			}
		}
		else
		{
				char * start = buf;
				while( *start )
				{
					if ( *start == '.' || *start == ',' )
						downloadCount ++;
					start ++;
				}
			cout << "Download size: " << downloadCount * 1024 << endl;
		}

		cout << buf;
		
//		cout << "\n, ƶһ½" << endl;
	}


	int exitCode = p->getExitCode();

	cout << " cmd exit with " << exitCode << endl;

	if ( exitCode != 0 )
		return false;

	return true;

}

bool unzip_file( const char * zip_cmd, const char * zipfile, const char * local_path )
{
	char buf[10000];
	sprintf( buf, "%s -uo \"%s\" -d \"%s\"", zip_cmd, zipfile ,local_path );
	cout << "exec cmd " << buf << " \t ";

	process * p = process::create( string(buf) );

	if ( p == NULL || ! p->isRunning() )
	{
		cout << " failed" << endl;
		return false;
	}

	cout << " starting" << endl;
	int size = 0;
	while( (size=p->read( buf, 999 )) > 0 )
	{
		buf[size] = '\0';
		cout << buf;
	}
	int exitCode = p->getExitCode();

	cout << " cmd exit with " << exitCode << endl;

	if ( exitCode != 0 )
		return false;

	return true;
}


bool test_update()
{
//	wget_download("http://www.vakaka.com/update/update20070723/" , "C:\\Program Files\\vakaka");
	bool download_ok = wget_download_file("c:\\share\\util\\wget.exe", "http://www.vakaka.com/update/update_200707231612.zip" , "C:\\Program Files\\vakaka\\update");

	if ( download_ok == false )
	{
		cout << "download fail!" << endl;
		return false;
	}

	bool unzip_ok = unzip_file( "c:\\share\\util\\unzip.exe", "C:\\Program Files\\vakaka\\update\\update_200707231612.zip" , "C:\\Program Files\\vakaka" );

	if ( unzip_ok == false )
	{
		cout << "unzip fail!" << endl;
		return false;
	}

	return true;
}

*/
